package org.dicker.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dicker.biz.TypeBiz;
import org.dicker.biz.impl.TypeBizImpl;
import org.dicker.entity.MessageInfo;
import org.dicker.entity.TypeInfo;
import org.lanqiao.mvc.entity.YockMvcAnnotation.Controller;
import org.lanqiao.mvc.entity.YockMvcAnnotation.RequestMapping;
import org.lanqiao.mvc.entity.YockMvcAnnotation.RequestParam;
import org.lanqiao.mvc.entity.YockMvcAnnotation.ResponseBody;

import cn.hutool.json.JSONUtil;

@Controller("/typeapi")
public class TypeApi {
	private TypeBiz tbiz = new TypeBizImpl();
	
	/**
	* showdoc
	* @catalog 分类管理模块
	* @title 查询分类信息
	* @description 这是一个查询分类信息的接口
	* @method post
	* @url http://192.168.10.6:8080/big-birds/typeapi/type-listapi.do
	* @param typename 可选  string 分类名称
	* @return [{"icon_url":"sad","type_name":"sad","type_id":1,"type_child_name":"sad","type_type":1},{"icon_url":"请问恶趣味","type_name":"sad王企鹅","type_id":2,"type_child_name":"艾维奇 ","type_type":2}] 
	* @return_param icon_url String 图标链接
	* @return_param type_name String 大分类名称
	* @return_param type_id int 分类id
	* @return_param type_child_name String 分类名称
	* @return_param type_type int 收支类型 0收入 1支出
	* @remark 这里是备注信息
	*/
	@RequestMapping(value = "/type-listapi.do")
	@ResponseBody
	public String index(
			HttpServletRequest req,
			HttpServletResponse res,
			@RequestParam(name = "typename") String typename)
					throws Exception{
		if(typename==null){
			typename="";
		}
		
		List<TypeInfo> tList = tbiz.selectByList(typename, -1, -1);
		
		String jsonStr = JSONUtil.toJsonStr(tList);
		
		res.setCharacterEncoding("utf-8");
		res.setContentType("text/json; charset=UTF-8");
				
		return jsonStr;
	}
}
